<script setup lang="ts">
import { ref } from "vue";
import KnowledgeCard from "./KnowledgeCard.vue";
import { KnowledgeType,KnowledgeParams,KnowledgeList } from "@/types/consult";
import {getKnowledgePage} from "@/services/consult"
const props=defineProps<{
  type:KnowledgeType
}>()

const loading=ref(false)
const finished=ref(false)
const list=ref<KnowledgeList>([])
const paramsData=ref<KnowledgeParams>({
  type:props.type,
  current:1,
  pageSize:5
})
const onLoad= async()=>{
  //发请求 ,改loading状态,判断是否最后一页改fiinished状态
  const res= await getKnowledgePage(paramsData.value)
  list.value.push(...res.data.rows)
  if(res.data.pageTotal>=paramsData.value.current){

    paramsData.value.current++

   }else{
    finished.value=true
   }
   loading.value=false
}
</script>

<template>
  <div class="knowledge-list">
    <van-list
    v-model:loading="loading"
    :finished="finished"
    finished-text="没有更多了"
    @load="onLoad"
    >
    <knowledge-card v-for="item in list" :key="item.id" :item="item"></knowledge-card>
    </van-list>
  </div>
</template>

<style lang="scss" scoped>
.knowledge-list {
  padding: 0 15px;
}
</style>
